package com.lagou.homework1_3;

import org.w3c.dom.ls.LSOutput;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

public class StudentTest {

    public static void main(String[] args) {
        //定义Map集合
        Map<Student, String> map = new HashMap<>();
        map.put(new Student("张三", 18), "月宫");
        map.put(new Student("李四", 28), "地球");
        map.put(new Student("王五", 38), "火星");

        //遍历1
        for (Student stu : map.keySet()) {
            System.out.println(stu + "::" + map.get(stu));
        }

        System.out.println("---------------------------------------");

        //遍历2
        for (Map.Entry<Student, String> m : map.entrySet()) {
            System.out.println(m.getKey() + "::" + m.getValue());
        }
        System.out.println("---------------------------------------");

        //遍历3
        Set<Map.Entry<Student, String>> entries = map.entrySet();
        Iterator<Map.Entry<Student, String>> iterator = entries.iterator();
        while (iterator.hasNext()) {
            Map.Entry<Student, String> next = iterator.next();
            System.out.println(next.getKey() + "::" + next.getValue());
        }

        System.out.println("---------------------------------------");

        //遍历4
        Iterator<Map.Entry<Student, String>> iterator1 = map.entrySet().iterator();
        while (iterator1.hasNext()) {
            Map.Entry<Student, String> next = iterator1.next();
            System.out.println(next.getKey() + "::" + next.getValue());
        }
    }
}
